package com.easyAiAdmin.web.controller.easyai;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.easyAiAdmin.common.annotation.Log;
import com.easyAiAdmin.common.core.controller.BaseController;
import com.easyAiAdmin.common.core.domain.AjaxResult;
import com.easyAiAdmin.common.enums.BusinessType;
import com.easyAiAdmin.easyai.domain.ModelConfig;
import com.easyAiAdmin.easyai.service.IModelConfigService;
import com.easyAiAdmin.common.utils.poi.ExcelUtil;
import com.easyAiAdmin.common.core.page.TableDataInfo;

/**
 * 模型参数配置Controller
 * 
 * @author easyAiAdmin
 * @date 2024-05-20
 */
@RestController
@RequestMapping("/model/config")
public class ModelConfigController extends BaseController
{
    @Autowired
    private IModelConfigService modelConfigService;

    /**
     * 查询模型参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('model:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelConfig modelConfig)
    {
        startPage();
        List<ModelConfig> list = modelConfigService.selectModelConfigList(modelConfig);
        return getDataTable(list);
    }

    /**
     * 导出模型参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('model:config:export')")
    @Log(title = "模型参数配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelConfig modelConfig)
    {
        List<ModelConfig> list = modelConfigService.selectModelConfigList(modelConfig);
        ExcelUtil<ModelConfig> util = new ExcelUtil<ModelConfig>(ModelConfig.class);
        util.exportExcel(response, list, "模型参数配置数据");
    }

    /**
     * 获取模型参数配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:config:query')")
    @GetMapping(value = "/{configCode}")
    public AjaxResult getInfo(@PathVariable("configCode") Long configCode)
    {
        return success(modelConfigService.selectModelConfigByConfigCode(configCode));
    }

    /**
     * 新增模型参数配置
     */
    @PreAuthorize("@ss.hasPermi('model:config:add')")
    @Log(title = "模型参数配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ModelConfig modelConfig)
    {
        return toAjax(modelConfigService.insertModelConfig(modelConfig));
    }

    /**
     * 修改模型参数配置
     */
    @PreAuthorize("@ss.hasPermi('model:config:edit')")
    @Log(title = "模型参数配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ModelConfig modelConfig)
    {
        return toAjax(modelConfigService.updateModelConfig(modelConfig));
    }

    /**
     * 删除模型参数配置
     */
    @PreAuthorize("@ss.hasPermi('model:config:remove')")
    @Log(title = "模型参数配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configCodes}")
    public AjaxResult remove(@PathVariable Long[] configCodes)
    {
        return toAjax(modelConfigService.deleteModelConfigByConfigCodes(configCodes));
    }
}
